//
//  ByUIAppIndexDevelopenttVC.m
//  chequanbao_ios
//
//  Created by pro on 17/5/27.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByUIAppIndexDevelopenttVC.h"

@interface ByUIAppIndexDevelopenttVC ()
{
    NSString *_title;
    NSString *_imageName;
    NSString *_content;
    NSString *_bottomImgName;
}
@property (nonatomic, strong) UIScrollView *scroll;
@end

@implementation ByUIAppIndexDevelopenttVC

- (instancetype)initWithTitle:(NSString *)title
                    imageName:(NSString *)imageName
                      content:(NSString *)content
                bottomImgName:(NSString *)bottomImgName{
    
    if ([super init]) {
        _title = title;
        _imageName = imageName;
        _content = content;
        _bottomImgName = bottomImgName;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = _title;
    self.isChangeColor = YES;
    [self addColorLeftBackBarButtonItem];
    UIImageView *bg = [self.view viewWithTag:888];
    bg.image = [UIImage imageWithColor:[UIColor colorWithWhite:0.98 alpha:1]];
    
    UIImage *image = [UIImage imageNamed:_imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH / image.size.width * image.size.height)];
    imageView.image = image;
    [self.scroll addSubview:imageView];
    

    NSAttributedString *str = [_content attributeString:15];
    CGRect rect = [_content getRectOfAttributeStringWithSize:CGSizeMake(self.scroll.width - 20, 10000) font:15];
//    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, imageView.bottom + 20, self.scroll.width - 20, [_content getRectOfStringWithSize:CGSizeMake(self.scroll.width - 20, 10000) font:15].size.height)];
     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, imageView.bottom + 20, self.scroll.width - 20,rect.size.height)];
    label.numberOfLines = 0;
    label.font = FONT(15);
//    label.text = _content;
    label.attributedText = str;
    label.textColor = [UIColor darkGrayColor];
    label.textAlignment = NSTextAlignmentLeft;
    [self.scroll addSubview:label];
    
    if (_bottomImgName != nil) {
        CGFloat height = 0;
        UIImage *img = [UIImage imageNamed:_bottomImgName];
        height = SCREEN_WIDTH / img.size.width * img.size.height;
        UIImageView *bottomImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, label.bottom + 20, SCREEN_WIDTH, height)];
        bottomImg.image = img;
        [self.scroll addSubview:bottomImg];
        self.scroll.contentSize = CGSizeMake(0, bottomImg.bottom + 20);
    } else {
        self.scroll.contentSize = CGSizeMake(0, label.bottom + 20);
    }
    
    
}
- (UIScrollView *)scroll {
    
    if (!_scroll) {
        _scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, self.view.width, SCREEN_HEIGHT - 64)];
        [self.view addSubview:_scroll];
    }
    return _scroll;
}



@end
